package com.itzdm.mapper;

import com.itzdm.pojo.Car;
import com.itzdm.pojo.Page;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface CarMapper {

    Long count();

    List<Car> pageSelect(Page page);

    @Select("select per_rent from car where vehicle_id = #{vehicleId}")
    Double getPerRent(Integer vehicleId);

    @Insert("insert into vehicle_status(user_id, begin_time, deadline) VALUES (#{userId},#{beginTime},#{deadline})")
    void addVehicleStatus(Integer userId, String beginTime, String deadline);

    @Select("select vehicle_status_id from vehicle_status where user_id = #{userId} and begin_time = #{beginTime} and deadline = #{deadline}")
    Integer getVehicleStatusId(Integer userId, String beginTime, String deadline);

    @Update("update car set vehicle_status_id = #{vehicleStatusId} where vehicle_id = #{vehicleId}")
    void updateStatus(Integer vehicleId, Integer vehicleStatusId);
}
